package com.myself.jndi;

import com.myself.IHelloBeanRemote;
import javax.naming.InitialContext;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;

/**
 * @author Kamel MAHDI
 */
public class Activator implements BundleActivator {
/**
 * 
 * @param bc
 * @throws Exception
 */
    public void start(BundleContext bc) throws Exception {
        ServiceReference sref = bc.getServiceReference(InitialContext.class.getName());
        if (sref == null)
           throw new IllegalStateException("Cannot access the InitialContext");
            InitialContext iniContext = (InitialContext)bc.getService(sref);
            IHelloBeanRemote helloBeanRemote = (IHelloBeanRemote) iniContext.doLookup("HelloBean");
            System.out.println("helloBeanRemote.sayHello() : "+ helloBeanRemote.sayHello());
    }
/**
 * 
 * @param bc
 * @throws Exception
 */
    public void stop(BundleContext bc) throws Exception {
        System.out.println("jndi bundle Stopped !");
    }
}
